package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Drugdictionary;
import com.ruoyi.web.service.IDrugdictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 药品清单Controller
 */
@RestController
@RequestMapping("/database/drugdictionary")
public class DrugdictionaryController extends BaseController {
    @Autowired
    private IDrugdictionaryService drugdictionaryService;

    /**
     * 查询药品清单列表
     */
    @PreAuthorize("@ss.hasPermi('database:drugdictionary:list')")
    @GetMapping("/list")
    public TableDataInfo list(Drugdictionary drugdictionary)
    {
        startPage();
        List<Drugdictionary> list = drugdictionaryService.selectDrugdictionaryList(drugdictionary);
        return getDataTable(list);
    }

    /**
     * 获取药品清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('database:drugdictionary:query')")
    @GetMapping(value = "/{drugId}")
    public AjaxResult getInfo(@PathVariable("drugId") Long drugId)
    {
        return success(drugdictionaryService.selectDrugdictionaryByDrugid(drugId));
    }

    /**
     * 新增药品清单
     */
    @PreAuthorize("@ss.hasPermi('database:drugdictionary:add')")
    @Log(title = "药品清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Drugdictionary drugdictionary)
    {
        return toAjax(drugdictionaryService.insertDrugdictionary(drugdictionary));
    }

    /**
     * 修改药品清单
     */
    @PreAuthorize("@ss.hasPermi('database:drugdictionary:edit')")
    @Log(title = "药品清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Drugdictionary drugdictionary)
    {
        return toAjax(drugdictionaryService.updateDrugdictionary(drugdictionary));
    }

    /**
     * 删除药品清单
     */
    @PreAuthorize("@ss.hasPermi('database:drugdictionary:remove')")
    @Log(title = "药品清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{drugIds}")
    public AjaxResult remove(@PathVariable Long[] drugIds)
    {
        return toAjax(drugdictionaryService.deleteDrugdictionaryByDrugids(drugIds));
    }
}
